<?php

namespace App\Http\Resources;

use App\Enums\WorkTicketTransferStatusEnum;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * @OA\Schema(
 *     schema="WorkTicketTransferResource",
 *     title="工单转接资源",
 *     description="工单转接信息",
 *     @OA\Property(property="id", type="integer", description="转接ID", example=1),
 *     @OA\Property(property="work_ticket_id", type="integer", description="工单ID", example=1),
 *     @OA\Property(property="from_work_user_id", type="integer", description="转出维护人员ID", example=1),
 *     @OA\Property(property="to_work_user_id", type="integer", description="转入维护人员ID", example=2),
 *     @OA\Property(property="remark", type="string", description="转接备注", example="专业不对口，转给电工师傅"),
 *     @OA\Property(property="status", type="integer", description="转接状态", example=100),
 *     @OA\Property(property="status_text", type="string", description="转接状态文本", example="待接受"),
 *     @OA\Property(property="accept_at", type="string", format="date-time", description="接受时间", example="2025-01-01 14:00:00"),
 *     @OA\Property(property="reject_at", type="string", format="date-time", description="拒绝时间", example="2025-01-01 14:00:00"),
 *     @OA\Property(property="created_at", type="string", format="date-time", description="创建时间", example="2025-01-01 12:00:00"),
 *     @OA\Property(property="updated_at", type="string", format="date-time", description="更新时间", example="2025-01-01 12:00:00")
 * )
 * @mixin \App\Models\WorkTicketTransfer
 */
class WorkTicketTransferResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'work_ticket_id' => $this->work_ticket_id,
            'work_ticket_code' => $this->workTicket?->code,
            'work_ticket' => new WorkTicketResource($this->whenLoaded('workTicket')),
            'from_work_user_id' => $this->from_work_user_id,
            'from_work_user_name' => $this->fromWorkUser?->real_name,
            'to_work_user_id' => $this->to_work_user_id,
            'to_work_user_name' => $this->toWorkUser?->real_name,
            'remark' => $this->remark,
            'status' => $this->status,
            'status_text' => WorkTicketTransferStatusEnum::getKey($this->status),
            'accept_at' => $this->accept_at?->toDateTimeString(),
            'reject_at' => $this->reject_at?->toDateTimeString(),
            'created_at' => $this->created_at?->toDateTimeString(),
            'updated_at' => $this->updated_at?->toDateTimeString(),
        ];
    }
} 